package exam;

public class EX01_SungJukDAO implements EX01_ISungJukDAO {

	
	private String DRV = "oracle.jdbc.driver.OracleDriver";
	private String URL = "jdbc:oracle:thin:cjhmasterola/cjhmasterola@112.216.253.125:1521:xe";
	private String insertSQL = "insert into EX01SUNGJUK values( ?, ?, ?, ?, ? )";
	
	private float kor;
	private float eng;
	private float mat;
	private float tot;
	private float avg;
	private String grade;
	@Override
		public boolean insertSungJuk(EX01_SungJukVO s) {
			Connection conn = null;
			PreparedStatement pstmt = null;
			boolean result = false;
			
			try{
				
				conn = this.openDatabase();
				pstmt = conn.prepareStatement(insertSQL);
					
					pstmt.setString(1, s.getKor() );
					pstmt.setString(2, s.getEng() );
					pstmt.setString(3, s.getMat() );
					pstmt.setString(4, s.getTot() );
					pstmt.setString(5, s.getAvg() );
				pstmt.executeUpdate();
				result = true;
				
				
			} catch ( Exception ex ) {
				ex.printStackTrace(); 
			}finally {
				closeDatabase(conn, pstmt, null);
			}	
			return result;
		}	// insertMember

		
		
		private Connection openDatabase(  ){
			try {
				Class.forName(DRV);
				return DriverManager.getConnection(URL);
			} catch (Exception e) {
						e.printStackTrace();
			}
			return null;
		}
		
		
		
	
		private void closeDatabase( Connection c, PreparedStatement p, ResultSet r){
			 
					if ( r != null) try { r.close(); r =  null; } catch ( Exception e) {} 
					if ( p != null) try { p.close(); p =  null; } catch ( Exception e) {} 
					if ( c != null) try { c.close(); c =  null; } catch ( Exception e) {} 
				
					
	}
	

	
	
	
	
}
